#ifndef RESULTREPORTER_H
#define RESULTREPORTER_H

#include "ConsoleColor.h"
#include "..\tdd.h"

template<typename Output>
class ResultReporterT : public TDD::Reporter
{
	Output& m_output;
	unsigned int m_testsRun, m_failedTests;
public:
	ResultReporterT(Output& output)
		: m_output(output)
		, m_testsRun(0)
		, m_failedTests(0)
	{}
	virtual ~ResultReporterT()
	{
		ConsoleColor cc;
		cc.SetFontAndBackgroundColors ( (WORD)(m_failedTests == 0 ? ConsoleColor::LightGreen : ConsoleColor::LightRed),
										(WORD)ConsoleColor::Black);
		if (m_testsRun == 0)
		{
			cc.SetFontAndBackgroundColors(ConsoleColor::Yellow, ConsoleColor::Black);
			m_output(L"No tests were run!!!\n");
		}
		else
		{
			CString cs;
			cs.Format(L"%i failure%s out of %i test%s run\n",
															m_failedTests,
															m_failedTests == 1 ? L"" : L"s",
															m_testsRun,
															m_testsRun == 1 ? L"" : L"s");
			m_output(cs);
		}
	}
	unsigned int TestsRun() const { return m_testsRun; }
	unsigned int TestsFailed() const { return m_failedTests; }

public: // TDD::Reporter
	virtual void ForEachTest   (const TDD::UnitTestInfo& ) { ++m_testsRun; }
	virtual void ForEachFailure(const TDD::TestFailure& tr)
	{
		++m_failedTests;

		CString cs;

		cs.Format(L"Failure in %S.%S -\n", tr.group, tr.testname);
		m_output(cs); // report namespace/class/test 

		cs.Format(L"%S(%ld) : ERROR : \"%S\"\n", tr.file_name, tr.line_number, tr.error_string);
		m_output(cs); // report file, line, and message
	}
};

#endif
